﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "ShaderLearn/C_11_3_Water" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Magnitude("Wave Magnitude",float) = 1
		_Frequency("Wave Frequency", float) = 10
		_InvWaveLength("Inv Wave Lenght", float) = 1
		_Speed("Move Speed", float) = 10
	}
	SubShader {
		Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType"="Transparent" }
		Pass
		{
			Tags{ "LightMode" = "ForwardBase" }
			ZWrite off
			//Blend SrcAlpha OneMinusSrcAlpha
			Blend One One

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

#include "UnityLightingCommon.cginc"
#include "UnityCG.cginc"

			fixed4 _Color;
			sampler2D _MainTex;
			float4 _MainTex_ST;
			float _Magnitude;
			float _Frequency;
			float _InvWaveLength;
			float _Speed;

			struct a2v
			{
				float4 vertex : POSITION;
				float4 texcoord : TEXCOORD0;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
				float2 uv : TEXCOORD2;
			};

			v2f vert(a2v v)
			{
				v2f o;
				float4 offset = float4(0, 0, 0, 0);
				float offset_rad = _Frequency * _Time.y + v.vertex.x * 0 +
					v.vertex.y * 0 + v.vertex.z * _InvWaveLength;
				offset.y = _Magnitude * sin(offset_rad);
				o.vertex = UnityObjectToClipPos(v.vertex + offset);
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex) + float2(0.0, _Time.x * _Speed);
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				fixed3 albedo = tex2D(_MainTex, i.uv).rgb * _Color.rgb;
				fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;

				return fixed4(ambient, 1.0);
			}

			ENDCG
		}
	} 
	FallBack "Diffuse"
}
